package leetcode;

import java.util.Scanner;

/**
 * ClassName: XiechengT1
 * Package: leetcode
 * Description:
 *
 * @Author wjn
 * @Create 2025/9/6 14:31
 * @Version 1.0
 */
public class XiechengT1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        scanner.nextLine(); // 消耗换行符
        String s = scanner.nextLine();
        char[] chars = s.toCharArray();
        int[] lastOp = new int[n]; // 0表示无操作，1表示转小写，2表示转大写

        for (int i = 0; i < m; i++) {
            String op = scanner.nextLine();
            if (op.startsWith("toLowerCase")) {
                // 提取括号中的数字
                int startIndex = op.indexOf('(');
                int endIndex = op.indexOf(')');
                String numStr = op.substring(startIndex + 1, endIndex);
                int x = Integer.parseInt(numStr);
                lastOp[x] = 1;
            } else if (op.startsWith("toUpperCase")) {
                int startIndex = op.indexOf('(');
                int endIndex = op.indexOf(')');
                String numStr = op.substring(startIndex + 1, endIndex);
                int x = Integer.parseInt(numStr);
                lastOp[x] = 2;
            }
        }

        // 根据记录的操作类型修改字符数组
        for (int i = 0; i < n; i++) {
            if (lastOp[i] == 1) {
                chars[i] = Character.toLowerCase(chars[i]);
            } else if (lastOp[i] == 2) {
                chars[i] = Character.toUpperCase(chars[i]);
            }
        }

        System.out.println(new String(chars));
    }
}
